package com.zookeeper.basic.two.zkclient;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.ZkClient;

import java.util.List;

/**
 * Created by 58 on 2016-7-17.
 * zkclient获取子节点信息
 */
public class ZkClientGetChildren {
    public static void main(String[] args) throws InterruptedException {
        String path = "/zk-book45";
        ZkClient client = new ZkClient("127.0.0.1:2181",5000);
        client.subscribeChildChanges(path, new IZkChildListener() {
            public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
                System.out.println(parentPath+" 's child changed ,currentChilds:"+currentChilds);

            }
        });
        client.createPersistent(path);
        Thread.sleep(1000);
        System.out.println(client.getChildren(path));
        client.createPersistent(path+"/c1");
        Thread.sleep(1000);
        client.delete(path+"/c1");
        Thread.sleep(1000);
        client.delete(path);
        Thread.sleep(Integer.MAX_VALUE);
    }

}
